//
// Created by jsjxsy on 2022/8/15.
// 相互友元类
//
#include <string>
#include <iostream>
using namespace std;
class Wife;
class Husband {
 public:
  string name;
  Husband(double s=20000.10,string n="zhang san"):salary(s),name(n){}
  ~Husband();
 private:
  double salary;
 public:
  friend class Wife;
  void visit(Wife &wife);
};

class Wife {
  friend class Husband;
 public:
  string name;
  Wife();
  ~Wife();
 private:
  double salary;
 public:
  void visit(Husband &husband);
  void takeMoney(double money);
  void takeHusbandMoney(double money, Husband &husband);
};

Husband::~Husband() {
  cout << "~Husband()" << endl;
}
void Husband::visit(Wife &wife) {
  cout << "wife name:" << wife.name << endl
       << "salary:" << wife.salary << endl;
}

Wife::Wife() {
  this->name = "xiao mei";
  this->salary = 15000.19f;
}

Wife::~Wife() {
  cout << "~Wife()" << endl;
}

void Wife::visit(Husband &husband) {
  cout << "husband name:" << husband.name << endl
       << "salary:" << husband.salary << endl;
}

void Wife::takeMoney(double money) {
  this->salary = this->salary - money;
}

void Wife::takeHusbandMoney(double money, Husband &husband) {
  husband.salary = husband.salary - money;
}

int main(void) {
  Husband husband;
  Wife wife;
  husband.visit(wife);
  wife.visit(husband);
  wife.takeHusbandMoney(100, husband);
  wife.visit(husband);
  wife.takeMoney(100);
  husband.visit(wife);
  return 0;
}
